package chapter17;



/**
 * @Auther: Tx
 * @Date: 2022/6/19 18:53
 */
//通过实现Runable接口方式，进行动态代理来实现线程
public class Thread02 {
    public static void main(String[] args) {
    //使用实现了Runable接口的类创建线程
        Tiger tiger = new Tiger();
//        这里不能调用start，要创建一个Thread类
        Thread thread = new Thread(tiger);
        thread.start();
    }
}
class Animal{}
class Tiger extends Animal implements Runnable{


    @Override
    public void run() {
        System.out.println("tiger scream");
    }
}


//模拟实现一个简单的Thread代理类
class ThreadProxy implements Runnable{
    private Runnable target;

    public ThreadProxy(Runnable target) {
        this.target = target;
    }

    @Override
    public void run() {
        if (target!=null){
            target.run();//动态绑定机制
        }
    }
    public void start(){
        start0();
    }
    public  void start0(){
        run();
    }
}